#include "garage.h"


#include <stdio.h>
#include <string.h>

     void init_garage(Garage *g){


        g->nbre = 0;
    }

    void afficher_garage(Garage g){

    int i;

        for (i=0;i<g.nbre;i++){

            afficher_voiture(g.tab[i]);

        }

    }

   void ajouter_voiture(Voiture v,Garage *g){

        if (g->nbre<TailleGarage)
        g->tab[g->nbre] = v ;
        (g->nbre) ++;


    }

   /* int saisie_position(Garage g){
            int p;
        do{
        printf("Donner la position\n");
        scanf("%d",&p);
        }while(p <=g.nbre);

        return p;


    }*/

    void supprimer_voiture(Garage *g,char matr[]){

        int i,p=g->nbre;
        int fait=0;


        for (i=0;i<=(g->nbre);i++){

		printf("standby...\n");

            if (strcmp(g->tab[i].immatriculation,matr)==0){
		printf("compar ok\n");
                p = i;

            }
        }



	printf("p:%d\n",p);

	printf("nbre:%d",(g->nbre)-2);

	if ((g->nbre-2) == 0) {

	for ( i=p; i <= (g->nbre-1) ;i++){

	g->tab[0] = g->tab[1];

	fait = 1; 

	}

	}

        for (i=p ; i <= (g->nbre-2) ;i++ ){

           g->tab[i] = g->tab[i+1];

	printf("i:%d",i);
	
           fait = 1;

        }

        if (g->nbre<2){

            fait = 1;

        }


        if (fait==1){

        (g->nbre)--;

        }




    }


